package com.fr.dialog.core;

import com.fr.base.FRContext;
import com.fr.base.Inter;
import com.fr.base.core.BaseCoreUtils;
import com.fr.base.core.ComparatorUtils;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.util.Locale;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JSpinner.DefaultEditor;
import javax.swing.SpinnerNumberModel;

public class UnitFieldPane extends JPanel
{
  private JSpinner valueSpinner;
  private boolean useLocale = false;

  public UnitFieldPane()
  {
    setLayout(new FlowLayout(0, 3, 0));
    this.valueSpinner = new JSpinner(new SpinnerNumberModel(0.0D, 0.0D, 1.7976931348623157E+308D, 1.0D));
    JFormattedTextField localJFormattedTextField = ((JSpinner.DefaultEditor)this.valueSpinner.getEditor()).getTextField();
    localJFormattedTextField.setColumns(4);
    add(this.valueSpinner);
    JLabel localJLabel = new JLabel();
    Locale localLocale = FRContext.getLocale();
    if (this.useLocale)
      if (ComparatorUtils.equals(Locale.CHINA, localLocale))
        localJLabel.setText(Inter.getLocText("PageSetup-mm"));
      else
        localJLabel.setText(Inter.getLocText("PageSetup-inches"));
    else
      localJLabel.setText(Inter.getLocText("PageSetup-mm"));
    Dimension localDimension = new Dimension(localJLabel.getPreferredSize().width, this.valueSpinner.getPreferredSize().height);
    localJLabel.setMinimumSize(localDimension);
    localJLabel.setMinimumSize(localDimension);
    localJLabel.setSize(localDimension);
    localJLabel.setPreferredSize(localDimension);
    add(localJLabel);
  }

  public double getInchesValue()
  {
    Locale localLocale = FRContext.getLocale();
    if (this.useLocale)
    {
      if (ComparatorUtils.equals(Locale.CHINA, localLocale))
        return BaseCoreUtils.convertMillimetersToInches(((Number)this.valueSpinner.getValue()).doubleValue());
      return ((Number)this.valueSpinner.getValue()).doubleValue();
    }
    return BaseCoreUtils.convertMillimetersToInches(((Number)this.valueSpinner.getValue()).doubleValue());
  }

  public void setInchesValue(double paramDouble)
  {
    Locale localLocale = FRContext.getLocale();
    if (this.useLocale)
      if (ComparatorUtils.equals(Locale.CHINA, localLocale))
        this.valueSpinner.setValue(new Double(BaseCoreUtils.convertInchesToMillimeters(paramDouble)));
      else
        this.valueSpinner.setValue(new Double(paramDouble));
    else
      this.valueSpinner.setValue(new Double(BaseCoreUtils.convertInchesToMillimeters(paramDouble)));
  }
}